package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TOrderMapper;
import com.ruoyi.system.domain.TOrder;
import com.ruoyi.system.service.ITOrderService;

import javax.annotation.Resource;

/**
 * 订单记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-08
 */
@Service
public class TOrderServiceImpl implements ITOrderService 
{
    @Resource
    private TOrderMapper tOrderMapper;

    /**
     * 查询订单记录
     * 
     * @param id 订单记录主键
     * @return 订单记录
     */
    @Override
    public TOrder selectTOrderById(Long id)
    {
        return tOrderMapper.selectTOrderById(id);
    }

    /**
     * 查询订单记录列表
     * 
     * @param tOrder 订单记录
     * @return 订单记录
     */
    @Override
    public List<TOrder> selectTOrderList(TOrder tOrder)
    {
        return tOrderMapper.selectTOrderList(tOrder);
    }

    /**
     * 新增订单记录
     * 
     * @param tOrder 订单记录
     * @return 结果
     */
    @Override
    public int insertTOrder(TOrder tOrder)
    {
        tOrder.setCreateTime(DateUtils.getNowDate());
        return tOrderMapper.insertTOrder(tOrder);
    }

    /**
     * 修改订单记录
     * 
     * @param tOrder 订单记录
     * @return 结果
     */
    @Override
    public int updateTOrder(TOrder tOrder)
    {
        tOrder.setUpdateTime(DateUtils.getNowDate());
        return tOrderMapper.updateTOrder(tOrder);
    }

    /**
     * 批量删除订单记录
     * 
     * @param ids 需要删除的订单记录主键
     * @return 结果
     */
    @Override
    public int deleteTOrderByIds(Long[] ids)
    {
        return tOrderMapper.deleteTOrderByIds(ids);
    }

    /**
     * 删除订单记录信息
     * 
     * @param id 订单记录主键
     * @return 结果
     */
    @Override
    public int deleteTOrderById(Long id)
    {
        return tOrderMapper.deleteTOrderById(id);
    }


    @Override
    public void saveShoppingCart(List<TOrder> tOrders,String userId) {
        //设置购物车订单ID
        String orderId = IdUtils.randomUUID();
//        User appUser = AppUserUtils.getAppUser();
        for (TOrder tOrder : tOrders) {
            tOrder.setOrderId(orderId);
            tOrder.setShoppingCart(1);
            tOrder.setUserId(userId);
            tOrderMapper.insertTOrder(tOrder);
        }
    }

//    @Override
//    public AjaxResult settleShoppingCart(Long ids) {
//        return null;
//    }
}
